package com.google.code.opengw.server.initializer;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.google.code.opengw.server.Constants;
import com.google.code.opengw.server.DataStore;
import com.google.code.opengw.server.Server;
import com.google.code.opengw.server.deployment.Deployment;
import com.google.code.opengw.server.domain.Domain;
import com.google.code.opengw.server.support.XMLParser;
import com.google.code.opengw.support.OpenGWException;

class PublishInitializer {
	
	private Domain domain;
	
	public PublishInitializer(Domain domain){
		this.domain = domain;
	}

	void initialize(File domainPath) throws OpenGWException, SAXException, IOException, ParserConfigurationException {
		/*
		 * START OF DEPLOYED PUBLISHMENT INITIALIZATION
		 */
		
		File[] files = domainPath.listFiles();
		for(File publishPath : files){
			if(!publishPath.isDirectory()
					|| publishPath.isHidden())
				continue;
			
			Deployment deployment = new Deployment(publishPath);
			domain.addPublish(XMLParser.parsePublish(domain, deployment));
		}

		/*
		 * END OF DEPLOYED PUBLISHMENT INITIALIZATION
		 */
	}
}
